package net.starwifi.duobao.web;

import net.starwifi.duobao.entity.Member;
import net.starwifi.duobao.mvc.*;
import net.starwifi.duobao.service.MemberService;
import net.starwifi.duobao.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by Administrator on 2015/9/28.
 */
@Controller("apiMemMessageController")
@RequestMapping("/member/message")
public class MsgController extends BaseController {


    @Autowired
    MemberService memberService;

    @Autowired
    MessageService messageService;
    /**
     * 列表
     */
    @ResponseBody
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Object list(int pageNum) {
        Member member=memberService.getCurrent();
        PageView pageView = new PageView(pageNum, 10);
        List<Order> orderBy=new ArrayList<Order>();
        orderBy.add(Order.desc("id"));
        final Page page = messageService.getScrollData(pageView," o.memberId=?1 or o.type=?2",new Object[]{member.getId(),1},orderBy);
        return Message.createMessage(Message.success("success"), new HashMap<String, Object>() {{
            put("list", page.getContent());
        }});
    }


}